package com.zoranjoka.chordis.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;

import com.zoranjoka.chordis.Artist;
import com.zoranjoka.chordis.beans.ArtistBean;
import com.zoranjoka.chordis.data.IDataArtist;

public class DataArtistHibernate implements IDataArtistService{

	private final Session session;
	
	public DataArtistHibernate(Session session){
		this.session = session;
	}
	
	/* (non-Javadoc)
	 * @see com.zoranjoka.chordis.hibernate.IDataArtistService#getAllArtists()
	 */
	@Override
	public List<ArtistBean> getAllArtists() {
		List getAll = session.createQuery("from ArtistBean").list();
        return getAll;
	}

	/* (non-Javadoc)
	 * @see com.zoranjoka.chordis.hibernate.IDataArtistService#getArtistByName(java.io.Serializable)
	 */
	@Override
	public Artist getArtistByName(Serializable id) {
		return (Artist) session.get(ArtistBean.class, id);
	}

	/* (non-Javadoc)
	 * @see com.zoranjoka.chordis.hibernate.IDataArtistService#addArtistBean(com.zoranjoka.chordis.beans.ArtistBean)
	 */
	@Override
	public Artist addArtistBean(Artist ab) {
		return (Artist)session.get(ArtistBean.class, session.save(ab));
		
	}

	
	

}
